﻿/**
 * 
 * @file GraphArea.h
 * @brief 绘图区域声明
 * @author LiBaojun (libaojunqd@foxmail.com)
 * @date 2024-10-15
 * 
 */
#ifndef __FITK_GRAPHH_AREA_H___
#define __FITK_GRAPHH_AREA_H___
 
#include "GUIWidgetAPI.h"
#include "FITK_Kernel/FITKCore/FITKAbstractGUI.h"
#include <QPushButton>

class QToolBar;

namespace Comp
{
    class FITKMdiArea;
}

namespace Ui
{
    class GraphArea;
}

namespace GUI
{
    class GraphArea;
    /**
     * @brief 绘图区域子窗口。抽象类
     * @author LiBaojun (libaojunqd@foxmail.com)
     * @date 2024-10-15
     */
    class GUIWIDGETAPI GraphAbstractSubWin : public Core::FITKWidget
    {
        Q_OBJECT
    public:
        /**
         * @brief 子窗口类型
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-18
         */
        enum SubWinType
        {
            None,       ///< 无类型
            Browser,    ///< 浏览窗口
            Pre3D,      ///< 3D窗口
        };

    public:
        /**
         * @brief Construct a new Graph Abstract Sub Win object
         * @param[i]  w              父对象
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        explicit GraphAbstractSubWin(GraphArea* w);
        /**
         * @brief Destroy the Graph Abstract Sub Win object
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        virtual ~GraphAbstractSubWin() = 0;
        /**
         * @brief 获取按钮
         * @return QPushButton* 
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        QPushButton* getPushButton();
        /**
         * @brief 获取窗口类型
         * @return SubWinType 
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-18
         */
        virtual SubWinType getSubWindowType() = 0;

    private slots:
        /**
         * @brief 按钮点击事件
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-18
         */
        void onButtonClickedSlot();

    protected:
        GraphArea* _graphArea{};
        /**
         * @brief 显示在底部窗口的按钮
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        QPushButton* _pushButton{};
    };

     /**
      * @brief 绘图区域声明
      * @author LiBaojun (libaojunqd@foxmail.com)
      * @date 2024-10-15
      */
    class GUIWIDGETAPI GraphArea : public Core::FITKWidget
    {
        Q_OBJECT
    public:
        /**
         * @brief Construct a new Graph Area object
         * @param[i]  parent         父对象
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        explicit GraphArea(QWidget* parent = nullptr);
        /**
         * @brief Destroy the Graph Area object
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        virtual ~GraphArea();
        /**
         * @brief 追加子窗口
         * @param[i]  subWin        子窗口
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        void addSubWindow(GraphAbstractSubWin* subWin);
        /**
         * @brief 获取当前窗口
         * @return QWidget* 
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        QWidget* getCurrentSubWin();
        /**
         * @brief    获取当前类型的所有子窗口
         * @param[i] type                                窗口类型
         * @return   QList<GraphAbstractSubWin*>         子窗口列表
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-03-05
         */
        QList<GraphAbstractSubWin*> getSubWindowsByType(GUI::GraphAbstractSubWin::SubWinType type);

        template<class T>
        /**
         * @brief 获取当前窗口并转换类型
         * @return T* 
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        T* getCurrentWindow()
        {
            return dynamic_cast<T*>(this->getCurrentSubWin());
        }
        /**
         * @brief 激活窗口，设置为当前窗口
         * @param[i]  w              子窗口
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-18
         */
        void activeSubWindow(QWidget* w);
        /**
         * @brief 获取第一个类型为type的子窗口
         * @param[i]  type             窗口类型
         * @return GraphAbstractSubWin
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-18
         */
        GraphAbstractSubWin* getFirstWindow(GraphAbstractSubWin::SubWinType type);
        /**
         * @brief 切换到一个类型为type的窗口
         * @param[i]  type             窗口类型
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-18
         */
        void switch2AWindow(GraphAbstractSubWin::SubWinType type);
        /**
         * @brief    创建新渲染窗口
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-03-04
         */
        void createNewPreWindow();
        /**
         * @brief    获取多视口区域
         * @return   Comp::FITKMdiArea*         多视口区域对象
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-03-04
         */
        Comp::FITKMdiArea* getMdiArea();
    private:
        /**
         * @brief 初始化工具栏
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        void initToolBar();


    private slots:
        /**
         * @brief 窗口被激活，工具栏显示状态
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-18
         */
        void subWindowActived();
        /**
         * @brief 3D窗口工具栏
         * @author wangning (2185896382@qq.com)
         * @date 2024-11-18
         */
        void slotToolBarActionEvent();

    private:
        /**
         * @brief 界面对象
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        Ui::GraphArea* _ui{};
        /**
         * @brief 工具条
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        QToolBar* _toolBar{};
        /**
         * @brief  多视口区域
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-15
         */
        Comp::FITKMdiArea* _mdiArea{};
    };
}


#endif
